<?php

namespace App\Http\Controllers;

use App\Models\Comment;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class CommentController extends Controller
{
    //
    public function index(Request $request){
        return DB::table('comments','c2')->select('*')->whereIn('c2.id',function ($query) use ($request){
            $query->from('comments', 'c')->join('d_d_books', 'productId', '=', 'dd_id')
                ->where('isbn','=',$request->isbn)
                ->groupBy('commentId')
                ->selectRaw('min(c.id)');
        })->orWhereIn('c2.id',function ($query) use ($request){
            $query->from('comments', 'c')->join('j_d_books', 'productId', '=', 'jd_id')
                ->where('isbn','=',$request->isbn)
                ->groupBy('commentId')
                ->selectRaw('min(c.id)');
        })->orderBy('time')->limit(3000)->get();
    }
}
